package com.inifitness.common.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 直接队列
 *
 * @author sunjinfeng
 * @version 1.0.0
 * @since 2023-02-01 17:04
 */
@Configuration
public class EventRabbitConfig {

  public static final String EVENT_QUEUE = "inifitness.event.queue";
  public static final String EVENT_EXCHANGE = "inifitness.event.exchange";
  public static final String EVENT_ROUTING = "inifitness.event.key";

  @Bean
  public Queue eventQueue() {
    return new Queue(EVENT_QUEUE, true);
  }

  @Bean
  DirectExchange eventExchange() {
    return new DirectExchange(EVENT_EXCHANGE);
  }

  @Bean
  Binding bindingEvent(@Qualifier("eventQueue") Queue eventQueue,
      @Qualifier("eventExchange") DirectExchange eventExchange) {
    return BindingBuilder.bind(eventQueue).to(eventExchange).with(EVENT_ROUTING);
  }

}

